// common服务 entity PageBean
package com.kuaidao.common.entity;

import com.github.pagehelper.Page;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 分页 bean
 */
@Data
public class PageBean<T> implements Serializable{
    /**
     * 当前页数据
     */
    List<T> data;
    /**
     * 当前页
     */
    int currentPage;
    /**
     * 总记录数
     */
    int total;
    /**
     * 每页条数
     */
    int pageSize = 100;
    /**
     * 总页数
     */
    int pageSizes;

    public PageBean() {

    }
    public PageBean(List<T> list) {
        if (list instanceof Page) {
            Page<T> page = (Page<T>) list;
            int curPageNum = page.getPageNum();
            if(curPageNum==0) {
                curPageNum=1;
            }
            this.currentPage = curPageNum;
            this.pageSize = page.getPageSize();
            this.total = (int)page.getTotal();
            this.pageSizes = page.getPages();
            this.data = page;
        }
    }
}